<?PHP
require_once("include/macro_dir.php");
require_once("include/user.php");
if(!log_check())
{
    echo "<script language='JavaScript'>location.href='?path=login';</script>";
    exit();
}
define("ADMIN_IN",1);
$redirect=$_GET['redirect']?$_GET['redirect']:"setting";
?>
<script language="JavaScript">
var onshow="<?PHP echo $redirect; ?>";
</script>
<script language="JavaScript">
function show(sid)
{
	document.getElementById(onshow).style.display="none";
	onshow=sid;
	document.getElementById(onshow).style.display="block";
}
</script>
<script language="JavaScript">
function logout()
{
	if(confirm("Are you sure to sing out?"))
		location.href="log.php?act=out";
	else
		return false;
}
</script>
<div id="admin">
<table width="100%" border="0">
<tr>
<td width="25%" valign="top" class="menu">
<div class="padding"><a href="#" onclick="show('setting')">Setting</a></div>
<div class="padding"><a href="#" onclick="show('user')">User</a></div>
<div class="padding"><a href="#" onclick="show('link')">Link</a></div>
<div class="padding"><a href="#" onclick="show('sidebar')">Sidebar</a></div>
<div class="padding"><a href="#" onclick="show('page')">Page</a></div>
<div class="padding"><a href="#" onclick="show('message')">Message</a></div>
<?php
	if(glob($PLUGIN_DIR.'/*/')!=null)
	{
		foreach(glob($PLUGIN_DIR.'/*') as $filename)
		{
			if(is_dir($filename))
			{
				sscanf($filename, $PLUGIN_DIR."/%s", $fn);
				echo "<div class=\"padding\"><a href=\"#\" onclick=\"show('".$fn."')\">".$fn."</a></div>";
			}
		}
	}
?>
<?php
// get plugin config
global $PLUGIN_DIR;
if(glob($PLUGIN_DIR.'/*/display.php')!=null)
{
	foreach(glob($PLUGIN_DIR.'/*/display.php') as $filename)
	{
		$preg='/.*\/(.*)\/display.php/';
		preg_match_all($preg,$filename,$n);
		echo "<div  class='padding'><a href='#' onclick='show(\"".$n[1][0]."\")'>".$n[1][0]."</a></div>\n";
	}
}
?>
<div  class="padding"><a href="#" onclick="logout()">Sign out</a></div>
</td>
<td valign="top" style="font-size:14px">
<?PHP
/*
* Display or Submit;
*/
if($_GET['submit'])
{
	if(file_exists("admin/submit.".$_GET['submit'].".php"))
	{
		include("admin/submit.".$_GET['submit'].".php");
	}
	else if(file_exists("plugin/".$_GET['submit']."/submit.".$_GET['submit'].".php"))
	{
		include("plugin/".$_GET['submit']."/submit.".$_GET['submit'].".php");
	}
}
else
{
    if(!($dadmin=opendir("admin")))
        echo "Read dirent failed.";
    while(FALSE!=($fname=readdir($dadmin)))
    {
        if(strstr($fname,"display") && $fname!="." && $fname!="..")
            include("admin/$fname");
    }
    closedir($dadmin);
	if(glob($PLUGIN_DIR.'/*/display.*.php')!=null)
	{
		foreach(glob($PLUGIN_DIR.'/*/display.*.php') as $filename)
		{
			include($filename);
		}
	}
}
?>
</td>
</tr>
</table>
</div><!-- End of admin -->
<script language="javascript">
show(onshow);
</script>
